// logToFile.js
const fs = require('fs');
const moment= require('moment');

function setupLogging() {
  const logStream = fs.createWriteStream('./logs/app.log', { flags: 'a' });
  const originalConsoleLog = console.log;
  console.log = function (message) {
    originalConsoleLog(message); // 在控制台打印日志
    logStream.write(moment().format('YYYY-MM-DD HH:mm:ss') + ':' + message + '\n'); // 将日志写入文件
  };
}

module.exports = setupLogging;
